package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.business.domain.PowerStation;
import com.ruoyi.business.domain.dto.PowerStationFormDTO;
import com.ruoyi.business.domain.dto.PowerStationQueryDTO;
import com.ruoyi.business.domain.vo.PowerStationVO;
import com.ruoyi.business.service.IPowerStationService;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电站管理Controller
 *
 * @author yangmeng
 * @date 2023-05-31
 */
@Api("电站管理")
@RestController
@RequestMapping("/business/station")
public class PowerStationController extends BaseController {

    @Autowired
    private IPowerStationService powerStationService;

    /**
     * 查询电站管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(PowerStationQueryDTO powerStation) {
        startPage();
        List<PowerStationVO> list = powerStationService.selectPowerStationList(powerStation);
        return getDataTable(list);
    }

    /**
     * 查询电站管理列表
     */
    @GetMapping("/select")
    public AjaxResult select() {
        return AjaxResult.success(powerStationService.selectPowerStationList(new PowerStationQueryDTO()));
    }


    /**
     * 获取电站管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:station:query')")
    @GetMapping(value = "/{powerStationId}")
    public AjaxResult getInfo(@PathVariable("powerStationId") Long powerStationId) {
        return success(powerStationService.selectPowerStationByPowerStationId(powerStationId));
    }

    /**
     * 新增电站管理
     */
    @PreAuthorize("@ss.hasPermi('business:station:add')")
    @Log(title = "电站管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PowerStationFormDTO powerStationFormDTO) {
        if (!powerStationService.checkNumberNameUnique(powerStationFormDTO)) {
            return error("新增'" + powerStationFormDTO.getStationName() + "'失败，电站名称已存在");
        }
        return toAjax(powerStationService.insertPowerStation(powerStationFormDTO));
    }

    /**
     * 修改电站管理
     */
    @PreAuthorize("@ss.hasPermi('business:station:edit')")
    @Log(title = "电站管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody PowerStationFormDTO powerStation) {
        if (!powerStationService.checkNumberNameUnique(powerStation)) {
            return error("修改'" + powerStation.getStationName() + "'失败，电站名称已存在");
        }
        return toAjax(powerStationService.updatePowerStation(powerStation));
    }

    /**
     * 删除电站管理
     */
    @PreAuthorize("@ss.hasPermi('business:station:remove')")
    @Log(title = "电站管理", businessType = BusinessType.DELETE)
    @PostMapping("delete/{powerStationIds}")
    public AjaxResult remove(@PathVariable Long[] powerStationIds) {
        return toAjax(powerStationService.deletePowerStationByPowerStationIds(powerStationIds));
    }
}
